<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/static/include/taglib.jsp"%>

<!DOCTYPE html>
<html>
<head>
	<title>商品分类</title>
	<%@ include file="/static/include/head.jsp" %>
</head>
<body>
<!-- 模态框（Modal） -->
<form id="inputForm" modelAttribute="goodsCat" action="${ctx}/product/goodsCat/save" method="post" class="form-horizontal" enctype="multipart/form-data">
	<!-- <div class="modal-content"> -->
		<div class="modal-header">
			<button class="close" type="button" data-dismiss="modal">×</button>
			<h4 class="modal-title" id="myModalLabel">商品分类维护</h4>
		</div>
		<div class="modal-body">
            <!-- error message here -->
            <div id="messageBox" class="alert alert-warning hide"></div>
			<tags:message content="${message}"/>
			<c:if test="${param.type eq 'add'}">
                <input type="hidden" id="pid" name="parent.id" value="${param.pid}" />
			</c:if>
			<c:if test="${param.type eq 'edit' and goodsCat.parent != null}">
				<input type="hidden" id="pid" name="parent.id" value="${goodsCat.parent.id}" />
			</c:if>
            <c:if test="${param.type eq 'edit'}">
				<input type="hidden" id="id" name="id" value="${goodsCat.id}" />
			</c:if>
                <!-- form filed -->
				<div class="form-group">
					<label class="col-sm-2 control-label no-padding-right">分类名称:</label>
					<div class="col-xs-6">
						<input type="text" id="name" name="name" value="${goodsCat.name}"
							   placeholder="分类名称" class="form-control  required  ">
					</div>
				</div>
                <!-- form filed -->
				<div class="form-group">
					<label class="col-sm-2 control-label no-padding-right">商品类型:</label>
					<div class="col-xs-6">
						<select id="goodsType.id" name="goodsType.id" class="form-control required">
						<option value="">--请选择商品类型--</option>
						<c:forEach items="${types }" var="type">
							<option value="${type.id }" <c:if test="${goodsCat.goodsType.id == type.id }">selected</c:if>>${type.name }</option>
						</c:forEach>
						</select>
					</div>
				</div>
                <!-- form filed -->
				<div class="form-group">
					<label class="col-sm-2 control-label no-padding-right">是否显示:</label>
					<div class="col-xs-6">
						<input type="radio" id="listShow" name="listShow" value="1" <c:if test="${goodsCat.listShow eq 1}">checked</c:if><c:if test="${empty goodsCat.listShow }">checked</c:if>> 是
						<input type="radio" id="listShow" name="listShow" value="0" <c:if test="${goodsCat.listShow eq 0}">checked</c:if>> 否
					</div>
				</div>
				<!-- form filed -->
				<div class="form-group">
					<label class="col-sm-2 control-label no-padding-right">排序:</label>
					<div class="col-xs-6">
						<input type="text" id="catOrder" name="catOrder" value="${goodsCat.catOrder}"
							   placeholder="排序" class="form-control  ">
					</div>
				</div>
                <!-- form filed -->
				<div class="form-group">
					<label class="col-sm-2 control-label no-padding-right">分类图片:</label>
					<div class="col-xs-6">
						<input type="file" id="imageFile" name="imageFile" accept="image/gif,image/jpg,image/jpeg,image/bmp,image/png">
					</div>
				</div>
				<c:if test="${!empty goodsCat.image }">
				<!-- form filed -->
				<div class="form-group">
					<label class="col-sm-2 control-label no-padding-right"></label>
					<div class="col-xs-6">
					<c:choose>
					<c:when test="${fn:startsWith(goodsCat.image, 'http')}">
						<img alt="" src="${goodsCat.image }" height="100px;">
					</c:when>
					<c:otherwise>
						<img alt="" src="${ctx }${goodsCat.image }" height="100px;">
					</c:otherwise>
					</c:choose>						
					</div>
				</div>
				</c:if>
		</div>
		<div class="modal-footer">
			<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            <c:if test="${param.type ne 'view'}">
			<button type="submit" class="btn btn-primary" onclick="doSubmit()">提交更改</button>
			</c:if>
		</div>
	<!-- </div> -->
</form>
<script>
	function doSubmit() {
        $("#inputForm").validate({
            submitHandler: function(form){
                form.submit();
            },
            errorContainer: "#messageBox",
            errorPlacement: function(error, element) {
                $("#messageBox").html('<div class="alert alert-danger">' +
					'<a href="#" class="close" data-dismiss="alert">&times;</a>' +
					'<strong>警告！</strong>输入有误，请进行一些更改。</div>');
                if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
                    error.appendTo(element.parent().parent());
                } else {
                    error.insertAfter(element);
                }
            }
        });
    }
</script>
</body>
</html>
